﻿@inject IDataCacheService _dataCacheService
@inject NavigationManager NavigationManager

<MList Dense Shaped Style="@Style" Class="@Class">
    <MListItemGroup Value="selectedItem" ValueChanged="ValueChanged"
                    >
        @foreach (var item in items)
        {
            <MBorder Value="@(selectedItem == item.Text)" Offset="false" Width="4" >
                <MListItem Value="@item.Text">
                    <MListItemIcon>
                        <MIcon Color="primary">@item.Icon</MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>@item.Text</MListItemTitle>
                    </MListItemContent>
                </MListItem>
                </MBorder>
                }
        </MListItemGroup>
</MList>

@code {
    [Parameter]
    public string Style { get; set; }
    [Parameter]
    public string Class { get; set; }
    readonly MenuItemModel[] items = new[]
{
        new MenuItemModel { Text = "概览", Icon = "mdi-view-compact" , Url = "admin/index"},
        new MenuItemModel { Text = "数据", Icon = "mdi-database" , Url = "admin/data"},
        new MenuItemModel { Text = "审核", Icon = "mdi-order-bool-ascending-variant" , Url = "contentcenter"},
        new MenuItemModel { Text = "工具", Icon = "mdi-hammer-screwdriver", Url = "admin/tools" },
        new MenuItemModel { Text = "备份", Icon = "mdi-cloud-upload", Url = "admin/listbackuparchives" },
        new MenuItemModel { Text = "看板娘的小卖铺", Icon = "mdi-shape", Url = "admin/listcommodities" },
        new MenuItemModel { Text = "定时任务", Icon = "mdi-calendar-check", Url = "admin/listtimedtasks" },
        new MenuItemModel { Text = "动态采集", Icon = IconType.News.ToIconString(), Url = "admin/listnews"  },
        new MenuItemModel { Text = "商店信息", Icon = IconType.Store.ToIconString() , Url = "admin/liststoreinfo"},
        new MenuItemModel { Text = "推荐", Icon =IconType.ThumbsUp.ToIconString() , Url = "admin/listrecommends"},
        new MenuItemModel { Text = "评论", Icon =IconType.Comment.ToIconString() , Url = "admin/listcomments"},
        new MenuItemModel { Text = "消息", Icon = "mdi-forum", Url = "admin/listmessages" },
        new MenuItemModel { Text = "用户", Icon = IconType.User.ToIconString() , Url = "admin/ListUsers" },
        new MenuItemModel { Text = "词条", Icon = IconType.Entry.ToIconString(), Url = "admin/ListEntries" },
        new MenuItemModel { Text = "文章", Icon = IconType.Article.ToIconString(), Url = "admin/ListArticles" },
        new MenuItemModel { Text = "视频", Icon = IconType.Video.ToIconString(), Url = "admin/ListVideos" },
        new MenuItemModel { Text = "标签", Icon = IconType.Tag.ToIconString(), Url = "admin/ListTags"  },
        new MenuItemModel { Text = "周边", Icon = IconType.Periphery.ToIconString(), Url = "admin/ListPeripheries" },
        new MenuItemModel { Text = "收藏", Icon = "mdi-heart-multiple", Url = "admin/ListFavoriteFolders" },
        new MenuItemModel { Text = "抽奖", Icon = IconType.Lottery.ToIconString() , Url = "admin/ListLotteries"},
        new MenuItemModel { Text = "投票", Icon =IconType.Vote.ToIconString(), Url = "admin/ListVotes" },
        new MenuItemModel { Text = "文件", Icon = "mdi-file-multiple " , Url = "admin/ListFiles"},
        new MenuItemModel { Text = "其他设置", Icon = "mdi-cog", Url = "admin/ManageHome" },
    };

    bool offset;
    StringNumber selectedItem = "概览";

    protected override void OnInitialized()
    {
        var item = items.FirstOrDefault(s => s.Url == NavigationManager.Uri.Replace(NavigationManager.BaseUri, ""));

        selectedItem = item?.Text ?? "概览";
    }

    public void ValueChanged(StringNumber index)
    {
        if(index!=null)
        {
            selectedItem = index;

            var item = items.FirstOrDefault(s => s.Text == index.ToString());
            if(item!=null&& string.IsNullOrWhiteSpace(item.Url)==false)
            {
                NavigationManager.NavigateTo(item.Url);
            }
        }

        
    }



}
